#include<bits/stdc++.h>
using namespace std;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int sum=0,f=0;
	char ch=gc();
	for(;!isdigit(ch);ch=gc())f|=(ch=='-');
	for(;isdigit(ch);ch=gc()) sum=((sum<<1)+(sum<<3)+(ch^48));
	return f?-sum:sum;
}
int n,k;
int a[10000011];
long long f[10000011];
priority_queue<long long,vector<long long>,greater<long long>> q1,q2;
int q[10000011],l,r;
long long ans = 0;
const int mod = 1000000007;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	n=read(),k=read();
	for(int i = 1;i <= n;i++) a[i]=read();
	memset(f,0x3f,sizeof(f));
	f[0] = 0;
	for(int i = 1;i <= k;i++)
	{
		while(l < r && a[q[r - 1]] <= a[i])
			r--;
		q[r++] = i;
		f[i] = a[q[l]];
	}
	for(int i = l;i < r - 1;i++)
		q1.push(f[q[i]] + a[q[i + 1]]);
	for(int i = k + 1;i <= n;i++)
	{
		while(l < r && q[l] < i - k)
		{
			if(l < r - 1)
				q2.push(f[q[l]] + a[q[l + 1]]);
			l++;
		}
		while(l < r && a[q[r - 1]] <= a[i])
		{
			r--;
			if(l < r)
				q2.push(f[q[r - 1]] + a[q[r]]);
		}
		if(l < r)
			q1.push(f[q[r - 1]] + a[i]);
		q[r++] = i;
		f[i] = f[i - k] + a[q[l]];
		while(!q2.empty() && q1.top() == q2.top())
			q1.pop(),q2.pop();
		if(!q1.empty())
			f[i] = min(f[i],q1.top());
	}
	for(int i = n,base = 1;i;i--,base = base * 23ll % mod)
		(ans += f[i] % mod * base) %= mod;
	printf("%lld",ans);
	return 0;
}